package com.x.client.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.client.model.SellCar;
import com.x.client.rpc.SellCarRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 卖车信息-PC端
 */
@RestController
@RequestMapping(value = "/sellCarPC")
public class SellCarPCController extends BaseController{

	@Reference
	private SellCarRpcService sellCarRpcService;// 卖车服务

	/**
	 * 查询全部卖车信息列表
	 * @param sellCar
	 * @return
	 */
	@RequestMapping(value = "/selectAllSellCarList", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel selectAllSellCarList(SellCar sellCar){
		if(sellCar.getSellCarCreateTimeEnd() != null){
			sellCar.setSellCarCreateTimeEnd(this.getDate(sellCar.getSellCarCreateTimeEnd(),1));
		}
		if(sellCar.getSellCarLicenceDateEnd() != null){
			sellCar.setSellCarLicenceDateEnd(this.getDate(sellCar.getSellCarLicenceDateEnd(),1));
		}
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", sellCarRpcService.selectSellCarList(sellCar));
	}

	/**
	 * 查询全部卖车信息数量
	 * @param sellCar
	 * @return
	 */
	@RequestMapping(value = "/selectAllSellCarListNum", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel selectAllSellCarListNum(SellCar sellCar){
		if(sellCar.getSellCarCreateTimeEnd() != null){
			sellCar.setSellCarCreateTimeEnd(this.getDate(sellCar.getSellCarCreateTimeEnd(),1));
		}
		if(sellCar.getSellCarLicenceDateEnd() != null){
			sellCar.setSellCarLicenceDateEnd(this.getDate(sellCar.getSellCarLicenceDateEnd(),1));
		}
		Map<String, Object> res = new HashMap<>();
		res.put("total", sellCarRpcService.selectSellCarListNum(sellCar));
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", res);
	}
}
